package org.jiamandan.com.strategy.impl.tram.listener;

import io.netty.channel.ChannelHandlerContext;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.jiamandan.com.constant.BizConstant;
import org.jiamandan.com.constant.JSYConstant;
import org.jiamandan.com.dto.JsyBasicDto;
import org.jiamandan.com.entity.RechargePile;
import org.jiamandan.com.strategy.impl.tram.IJSYDZBasicListener;
import org.jiamandan.com.utils.JsyObjectUtil;
import org.springframework.stereotype.Service;


@Service(value = JSYConstant.Service.CMD_JSY_T00003_SERVICE)
@AllArgsConstructor
@Slf4j
public class JSYQueryStatusListener implements IJSYDZBasicListener {


    @Override
    public void doExecute(String payload, ChannelHandlerContext client) throws Exception {
        log.info("嘉满电-JSY设备端口最新状态应答(CMD = T00003)：" + payload);
        JsyBasicDto jsyBasicDto = JsyObjectUtil.parse(payload);
        String[] items = StringUtils.split(jsyBasicDto.getData(), BizConstant.separator);
        String pileNo = jsyBasicDto.getDeviceNo();
        log.info("嘉满电-JSY设备端口最新状态应答:设备号:"+jsyBasicDto.getDeviceNo()+"端口数量"+items[0]+"端口状态:"+items[1]);
        int num = Integer.valueOf(items[0]);

        /**
         * code编码{单路、双路、四路、10路、12路、16路、漏保主机}
         */
        log.info("嘉满电-JSY设备充电编码code={},num={}",10,num);
        for (int i = 0; i < num; i++) {
            log.info("嘉满电-JSY设备充电编码={},更新状态",pileNo);
        }
    }
}
